﻿@page "/"
@inject NavigationManager NavigationManager

<div class="home-page">
    <MCard>
        <img src="https://tucang.cngal.top/api/image/show/47560a67088d68778f872c64ba8ad338?https://image.cngal.org/images/upload/20231108/b10db068dafcc6df54bb6a665a7070d7c7331196.png">
        <MCardTitle>
            CnGal资料站 - 开放平台
        </MCardTitle>
        <MCardSubtitle>
            @if (StaticOptions.IsSSR)
            {

                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                var date = File.GetLastWriteTime(assembly.Location);
                <span>最后更新日期：@date.ToString("yyyy年M月d日")</span>
            }
            else
            {
                <span>最后更新日期：2023年3月18日</span>
            }

        </MCardSubtitle>
        <MCardText>
            <ul>
                <AuthorizeView>
                    <Authorized>
                        <li>
                            欢迎，@context.User.Identity.Name
                        </li>
                    </Authorized>
                    <NotAuthorized>
                        <li>
                            点击 <a @onclick="OnLogin">这里</a> 登入
                        </li>
                    </NotAuthorized>
                </AuthorizeView>
             
                <li>
                    我们提供
                    <a href="@(StaticOptions.IdsUrl+".well-known/openid-configuration")" target="_blank">发现文档</a>，里面包含：<strong>元数据，终结点链接，关键材料......</strong>
                </li>

                <li>
                    同时我们也创建了对外API的 <a href="@(StaticOptions.IdsUrl+"swagger/index.html")" target="_blank">Swagger文档</a>
                </li>
                <li>
                    这是
                    <a href="https://github.com/identityserver/IdentityServer4" target="_blank">源代码仓库</a> 的链接，
                    包含 <a href="https://github.com/IdentityServer/IdentityServer4/tree/main/samples" target="_blank">可使用的样例</a>
                </li>
            </ul>
        </MCardText>
    </MCard>

</div>

@code {
    protected void OnLogin()
    {
        InteractiveRequestOptions requestOptions = new()
        {
            Interaction = InteractionType.SignIn,
            ReturnUrl = NavigationManager.Uri,
        };


        if (StaticOptions.IsSSR)
        {
            NavigationManager.NavigateTo($"Account/Login?returnUrl={NavigationManager.Uri}", true);
        }
        else
        {
            NavigationManager.NavigateToLogin("authentication/login", requestOptions);
        }
    }
}
